package dao

import javax.inject.Inject
import models.Tables._
import play.api.db.slick.{DatabaseConfigProvider, HasDatabaseConfigProvider}
import slick.jdbc.JdbcProfile

import scala.concurrent.{ExecutionContext, Future}

class CmDao @Inject()(protected val dbConfigProvider: DatabaseConfigProvider)
                     (implicit exec: ExecutionContext) extends
  HasDatabaseConfigProvider[JdbcProfile]  {

  import profile.api._

  def insertGene(row: Seq[CmRow]): Future[Unit] = {
    db.run(Cm ++= row).map(_ => ())
  }

  def getAllGene: Future[Seq[CmRow]] = {
    db.run(Cm.result)
  }

  def getById(id: Int):Future[CmRow] = {
    db.run(Cm.filter(_.id === id).result.head)
  }

  def getByGeneIds(geneIds:Seq[String]) : Future[Seq[CmRow]] = {
    db.run(Cm.filter(_.geneid.inSetBind(geneIds)).result)
  }

  def getByGeneId(geneid:String) : Future[CmRow] = {
    db.run(Cm.filter(_.geneid === geneid).result.head)
  }

}
